#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<cstring>
class Solution {
public:
	string reverseOnlyLetters(string s)
	{
		if (s.empty())
			return s;

		int begin = 0;
		size_t end = s.size() - 1;
		while (begin < end)
		{
			while (begin < end && pd(s[begin]) == false)
			{
				begin++;
			}
			while (begin < end && pd(s[end]) == false)
			{
				end--;
			}

			std::swap(s[begin], s[end]);
			++begin;
			--end;
		}
		return s;
	}

	bool pd(char ch)
	{
		if (ch >= 'A' && ch <= 'Z')
			return true;

		if (ch >= 'a' && ch <= 'z')
			return true;

		return false;
	}

	
};
